package com.czk.netty.nio.basic;

import java.nio.ByteBuffer;

/**
 * readOnly的demo
 * @Author:ChenZhangKun
 * @Date: 2021/1/11 21:03
 */
public class ReadOnlyBuffer {
    public static void main(String[] args) {
        ByteBuffer byteBuffer=ByteBuffer.allocate(64);
        for (int i = 0; i < 64; i++) {
            byteBuffer.put((byte)i);

        }
        // 读
        byteBuffer.flip();
        // 得到只读的buffer
        ByteBuffer buffer = byteBuffer.asReadOnlyBuffer();
        System.out.println(buffer.getClass());
        // 读取
        while (buffer.hasRemaining()){
            System.out.println(buffer.get());
        }
    }
}
